package atm.zhaz;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;

public class MainWindow extends JFrame {
	MyClient client;
	JButton checkB, withdrawM, sendM, depositM, logout;
	JDialog parent;

	public MainWindow(MyClient c) {
		client = c;
		setLayout(null);


		checkB = new JButton("Check balance");
		withdrawM = new JButton("Withdraw Money");
		sendM = new JButton("Send Money");
		depositM = new JButton("Deposit");
		logout = new JButton("Cancel");

		checkB.setBounds(70, 50, 150, 30);
		withdrawM.setBounds(70, 90, 150, 30);
		sendM.setBounds(70, 130, 150, 30);
		depositM.setBounds(70, 170, 150, 30);
		logout.setBounds(70, 210, 150, 30);

		add(checkB);
		add(withdrawM);
		add(sendM);
		add(depositM);
		add(logout);

		setSize(300, 350);
		setLocation(350, 100);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		MyActionSluwatel ch = new MyActionSluwatel();
		checkB.addActionListener(ch);
		withdrawM.addActionListener(ch);
		sendM.addActionListener(ch);
		depositM.addActionListener(ch);
		logout.addActionListener(ch);

	}

	@Override
	public JDialog getParent() {
		return parent;
	}

	public void setParent(JDialog parent) {
		this.parent = parent;
	}


	public void showMessage(String s) {
		MessageWindow w = new MessageWindow(s);
		w.setVisible(true);
		System.out.println(s);
	}

	class MyActionSluwatel implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			if (e.getSource().equals(checkB)) {
				long k = client.balance();
				showMessage("balance is: " + k);
			} else if (e.getSource().equals(logout)) {
				getParent().setVisible(true);
				setVisible(false);
			} else if (e.getSource().equals(withdrawM)) {
				WithdrawWindow f = new WithdrawWindow(client);
				f.setVisible(true);
			} else if (e.getSource().equals(depositM)) {
				DepositWindow f = new DepositWindow(client);
				f.setVisible(true);
			} else if (e.getSource().equals(sendM)) {
				SendWindow f = new SendWindow(client);
				f.setVisible(true);
			}
		}
	}
}
